package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.system.domain.HyrjMachine;
import com.ruoyi.system.domain.HyrjMachineFaults;
import com.ruoyi.system.service.IHyrjMachineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HyrjMachineDisinfectionMapper;
import com.ruoyi.system.domain.HyrjMachineDisinfection;
import com.ruoyi.system.service.IHyrjMachineDisinfectionService;

/**
 * 洗衣机消毒管理，用于记录洗衣机的消毒操作信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-08
 */
@Service
public class HyrjMachineDisinfectionServiceImpl implements IHyrjMachineDisinfectionService {
    @Autowired
    private HyrjMachineDisinfectionMapper hyrjMachineDisinfectionMapper;

    @Autowired
    private IHyrjMachineService hyrjMachineService;


    /**
     * 查询洗衣机消毒管理，用于记录洗衣机的消毒操作信息
     *
     * @param id 洗衣机消毒管理，用于记录洗衣机的消毒操作信息主键
     * @return 洗衣机消毒管理，用于记录洗衣机的消毒操作信息
     */
    @Override
    public HyrjMachineDisinfection selectHyrjMachineDisinfectionById(Long id) {
        return hyrjMachineDisinfectionMapper.selectHyrjMachineDisinfectionById(id);
    }

    /**
     * 查询洗衣机消毒管理，用于记录洗衣机的消毒操作信息列表
     *
     * @param hyrjMachineDisinfection 洗衣机消毒管理，用于记录洗衣机的消毒操作信息
     * @return 洗衣机消毒管理，用于记录洗衣机的消毒操作信息
     */
    @Override
    public List<HyrjMachineDisinfection> selectHyrjMachineDisinfectionList(HyrjMachineDisinfection hyrjMachineDisinfection) {

        return hyrjMachineDisinfectionMapper.selectHyrjMachineDisinfectionList(hyrjMachineDisinfection);
    }

    /**
     * 新增洗衣机消毒管理，用于记录洗衣机的消毒操作信息
     *
     * @param hyrjMachineDisinfection 洗衣机消毒管理，用于记录洗衣机的消毒操作信息
     * @return 结果
     */
    @Override
    public int insertHyrjMachineDisinfection(HyrjMachineDisinfection hyrjMachineDisinfection) {
        HyrjMachine hyrjMachine = hyrjMachineService.selectHyrjMachineByNo(hyrjMachineDisinfection.getMachineNo());
        if (null != hyrjMachine) {
            hyrjMachine.setMachineStatus("4");
            hyrjMachineService.updateHyrjMachine(hyrjMachine);
        }
        hyrjMachineDisinfection.setDisinfectionTime(hyrjMachineDisinfection.getDisinfectionTime());
        hyrjMachineDisinfection.setDisinfectionStatus("1");
        return hyrjMachineDisinfectionMapper.insertHyrjMachineDisinfection(hyrjMachineDisinfection);
    }

    /**
     * 修改洗衣机消毒管理，用于记录洗衣机的消毒操作信息
     *
     * @param hyrjMachineDisinfection 洗衣机消毒管理，用于记录洗衣机的消毒操作信息
     * @return 结果
     */
    @Override
    public int updateHyrjMachineDisinfection(HyrjMachineDisinfection hyrjMachineDisinfection) {
        return hyrjMachineDisinfectionMapper.updateHyrjMachineDisinfection(hyrjMachineDisinfection);
    }


    @Override
    public int updateHyrjMachine(HyrjMachineDisinfection hyrjMachineDisinfection) {
        hyrjMachineDisinfection.setDisinfectionStatus("2");
        hyrjMachineDisinfection.setDisinfectionTime(new Date());
        hyrjMachineDisinfectionMapper.updateHyrjMachineDisinfection(hyrjMachineDisinfection);

        HyrjMachine hyrjMachine = hyrjMachineService.selectHyrjMachineByNo(hyrjMachineDisinfection.getMachineNo());
        hyrjMachine.setMachineStatus("1");
        return hyrjMachineService.updateHyrjMachine(hyrjMachine);

    }


    /**
     * 批量删除洗衣机消毒管理，用于记录洗衣机的消毒操作信息
     *
     * @param ids 需要删除的洗衣机消毒管理，用于记录洗衣机的消毒操作信息主键
     * @return 结果
     */
    @Override
    public int deleteHyrjMachineDisinfectionByIds(Long[] ids) {
        return hyrjMachineDisinfectionMapper.deleteHyrjMachineDisinfectionByIds(ids);
    }

    /**
     * 删除洗衣机消毒管理，用于记录洗衣机的消毒操作信息信息
     *
     * @param id 洗衣机消毒管理，用于记录洗衣机的消毒操作信息主键
     * @return 结果
     */
    @Override
    public int deleteHyrjMachineDisinfectionById(Long id) {
        return hyrjMachineDisinfectionMapper.deleteHyrjMachineDisinfectionById(id);
    }
}
